var Square = pi.base.extend({
    "$Init":function(_x,_y){
        this.environment.setX(_x).environment.setY(_y);
        return this;
    },
    "getName":function(_captured,_checked,_castling,_promotion){
      var mark = Piece.Naming[main.engine.environment.getDefaultLanguage()].mark[ 6-this.environment.getPiece().environment.getValue() ];
      return _castling&&(_castling==Piece.KINGSIDE&&"O-O"||"O-O-O")||"%(char)%(capture)%(rank)%(file)%(sign)%(promotion)".format({
        "char":this.environment.getPiece().environment.getValue()==1?"":mark,
        "rank":String.fromCharCode(this.environment.getX()+97),
        "file":this.environment.getY()+1,
        "capture":_captured&&"x"||"",
        "sign":_checked&&"+"||"",
        "promotion":_promotion&&"=Q"||""
      });
    },
    "getLeft":function(){
        return this.environment.getX()*50;
    },
    "getTop":function(_piece){
        return Table.FixVerticalDirection(this,_piece||this.environment.getPiece())*50;
    },
    "environment":{
        "_piece":null, "_time":0,
        "_x":-1, "_y":-1,
        "setPiece":function(_value){
            console.log("@Setting piece of ",this.getX()+"x"+this.getY()," to -> ",_value);
            if(_value&&this.getPiece()){
                    this.getPiece().remove();
            }
            this._setPiece(_value);
            if(_value){
                _value.environment.setSquare(this._parent_);
            }
            return this._parent_;
        }
    }
});
